package com.example.qimo.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.qimo.data.Bill
import com.example.qimo.databinding.ItemBillBinding

class BillAdapter(private val bills: List<Bill>) :
    RecyclerView.Adapter<BillAdapter.BillViewHolder>() {

    inner class BillViewHolder(val binding: ItemBillBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BillViewHolder {
        val binding = ItemBillBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return BillViewHolder(binding)
    }

    override fun onBindViewHolder(holder: BillViewHolder, position: Int) {
        val bill = bills[position]
        with(holder.binding) {
            // 设置账单项视图的内容
            billAmount.text = bill.amount.toString()
            billCategory.text = bill.category
        }
    }

    override fun getItemCount() = bills.size
}
